//package com.asset.crm.dao;
//
//
//import java.util.ArrayList;
//
//import org.hibernate.Query;
//
//import org.hibernate.Criteria;
//import org.hibernate.Session;
//import org.hibernate.SessionFactory;
//import org.hibernate.criterion.Restrictions;
//import org.hibernate.search.FullTextSession;
//import org.hibernate.search.Search;
//import org.springframework.beans.factory.annotation.Autowired;
//import org.springframework.stereotype.Repository;
//
//import java.util.List;
//
//import com.asset.crm.domain.Contact;
//
//@Repository
//public class ContactDaoImpl {
//	
//	@Autowired
//	private SessionFactory sessionFactory;
//	
//	
//	public void addContact(Contact contact) {
//		try{
//			  System.out.println("Donnnnnnnnnnnnnnnnnnnnnnnnnnne");
//		sessionFactory.getCurrentSession().save(contact);
//		}catch(Exception ex){
//			ex.printStackTrace();
//		}
//	}
//	public Contact getContact(Integer id) {
//		return (Contact)sessionFactory.getCurrentSession().get(Contact.class, id);
//	}
//	public void saveOrUpdate(Contact contact) {
//		sessionFactory.getCurrentSession().saveOrUpdate(contact);
//	}
//	@SuppressWarnings("unchecked")
//	public List<Contact> getAllContactByEmpId(Integer id) {
//		Session session = sessionFactory.getCurrentSession();
//		Query query = session.createQuery("from Contact where creator.id = :id and isDeleted= :isDeleted") ;
//		query.setParameter("id", id);
//		query.setParameter("isDeleted", false);
//		List<Contact> contacts = new ArrayList<Contact>();
//		contacts = query.list();
//		return contacts;
//		
//	}
//	
//	@SuppressWarnings("unchecked")
//	public List<Contact> getByParent( String typeId, Integer parentId) {
//		Session session =sessionFactory.getCurrentSession();
//		Query query = session.createQuery("from Contact where isDeleted= :isDeleted and viewType=:typeId and parentId= :parentId");
//		query.setParameter("isDeleted", false);
//		query.setParameter("typeId", typeId);
//		query.setParameter("parentId", parentId);
//		List<Contact> contacts= new ArrayList<Contact>();
//		contacts = query.list();
//		System.out.println(" xxxxxxxxxxxxxxxxxxx"+query.toString());
//		System.out.println("parent id xxxxxxxxxxxxxxxxxxx"+contacts.size());
//		return  contacts;
//	}
//	
//	@SuppressWarnings("unchecked")
//	public Contact getContactByParent( String typeId,Integer empId) {
//		Session session =sessionFactory.getCurrentSession();
//		Query query = session.createQuery("from Contact where isDeleted= :isDeleted and creator.id=:empId and viewType=:typeId");
//		query.setParameter("isDeleted", false);
//		query.setParameter("empId", empId);
//		query.setParameter("typeId", typeId);
//		List<Contact> contacts= new ArrayList<Contact>();
//		contacts = query.list();
//		System.out.println(" xxxxxxxxxxxxxxxxxxx"+query.toString());
//		System.out.println("parent id xxxxxxxxxxxxxxxxxxx"+contacts.size());
//		if(contacts.size()>0){
//			return  contacts.get(0);
//		}
//		else{
//			return null;
//		}
//		
//	}
//	
//	@SuppressWarnings("unchecked")
//	public List<Contact> getAllContact(Integer index) {
//		Session session =sessionFactory.getCurrentSession();
//		Query query = session.createQuery("from Contact where isDeleted= :isDeleted");
//		query.setParameter("isDeleted", false);
//		query.setFirstResult((index*5));
//		query.setMaxResults(5);
//		List<Contact> contacts= new ArrayList<Contact>();
//		contacts = query.list();
//		return  contacts;
//	}
//	
//	@SuppressWarnings("unchecked")
//	public List<Contact> getAllContactForCompany(Integer index,String companyName,Integer count) {
//		Session session =sessionFactory.getCurrentSession();
//		Query query = session.createQuery("from Contact con where con.isDeleted= :isDeleted and con.creator.company.companyName = :companyName");
//		query.setParameter("isDeleted", false);
//		query.setParameter("companyName", companyName);
//		query.setFirstResult((index*count));
//		query.setMaxResults(count);
//		List<Contact> contacts= new ArrayList<Contact>();
//		contacts = query.list();
//		return  contacts;
//	}
//	
//	
//	
//	@SuppressWarnings("unchecked")
//	public Integer getAllContactForCompanySize(String companyName) {
//		Session session =sessionFactory.getCurrentSession();
//		Query query = session.createQuery("from Contact con where isDeleted= :isDeleted and con.creator.company.companyName = :companyName");
//		query.setParameter("isDeleted", false);
//		query.setParameter("companyName", companyName);
//		List<Contact> contacts= new ArrayList<Contact>();
//		contacts = query.list();
//		return  contacts.size();
//
//	}
//	
//	
//	@SuppressWarnings("unchecked")
//	public Integer getAllContactSize() {
//		Session session =sessionFactory.getCurrentSession();
//		Query query = session.createQuery("from Contact where isDeleted= :isDeleted");
//		query.setParameter("isDeleted", false);
//		List<Contact> contacts= new ArrayList<Contact>();
//		contacts = query.list();
//		return  contacts.size();
//
//	}
//
//	@SuppressWarnings("unchecked")
//	public List<Contact> getAllContactbyCompany(String companyName) {
//		Session session =sessionFactory.getCurrentSession();
//		Query query = session.createQuery("from Contact con where con.isDeleted= :isDeleted and con.creator.company.companyName = :companyName");
//		query.setParameter("isDeleted", false);
//		query.setParameter("companyName", companyName);
//		List<Contact> contacts= new ArrayList<Contact>();
//		contacts = query.list();
//		return  contacts;
//	}
//	
//	@SuppressWarnings({ "unchecked", "unused" })
//	public List<Contact> getAllContactByName(String name,String companyName) {
//		Session session =sessionFactory.getCurrentSession();
//		
//        Criteria criteria = session.createCriteria(Contact.class).createAlias("creator.company", "company");
//        criteria.add(Restrictions.like("fName", "%" + name + "%"));
//        criteria.add(Restrictions.eq("isDeleted", false));
//        criteria.add(Restrictions.eq("company.companyName", companyName));
////        List<Contact>contacts = new ArrayList<Contact>();
////        contacts = criteria.list();
//        List results = criteria.list();
//		
////		Query query = session.createQuery("from Contact con where con.isDeleted= :isDeleted and lower(con.fName) like:name or lower(con.lName) like:name and con.creator.company.companyName = :companyName");
////		query.setParameter("isDeleted", false);
////		name = name.toLowerCase();
////		String names = "%"+name+"%";
////		query.setParameter("name", names);
////		query.setParameter("companyName", companyName);
////		List<Contact> contacts= new ArrayList<Contact>();
////		contacts = query.list();
//        if(results.size()>0){
//        	return  results;
//        }
//        else{
//        	return null;
//        }
//		
//	}
//	
//	public void deleteContact(Integer id) {
//		Contact contact = (Contact) sessionFactory.getCurrentSession().load(
//				Contact.class, id);
//		if (null != contact) {
//			sessionFactory.getCurrentSession().delete(contact);
//		}
//		
//		
//	}
//
//	
//	
//	
//}
